package cn.edu.xmu.datamining.tangzk.mralgos.kmeans;

import org.apache.hadoop.io.RawComparator;
import org.apache.hadoop.io.WritableComparator;

/**
 * only compare the cluster label from key when grouping values in reducer.
 * 
 * @version 2013-8-5
 * @author tangzk
 * @Reviewer
 * 
 */
public class KMeansGrouper implements RawComparator<ClusterCentroidWritable> {

	private static final int INT_LEN = Integer.SIZE / 8;

	@Override
	public int compare(ClusterCentroidWritable o1, ClusterCentroidWritable o2) {
		return o1.getC() - o2.getC();
	}

	@Override
	public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
		return WritableComparator
				.compareBytes(b1, s1, INT_LEN, b2, s2, INT_LEN);
	}

}
